'use strict';
const db = uniCloud.database();

exports.main = async (event, context) => {
  try {
    const collection = db.collection('Disclaimers');
    const res = await collection.where({
      popupVisible:true // 只获取状态为启用的公告
    }).orderBy('createTime', 'desc').field({
      popupVisible: true,
      popupType: true,
      createTime: true,
      updateTime: true,
      popupTitle: true,
      popupContent: true,
	  popupIsShow:true
    }).get();
    
    
    if (!res.data || res.data.length === 0) {
      console.warn('没有找到状态为启用的公告数据');
    }
    
    return {
      code: 0,
      msg: '获取成功',
      data: res.data
    };
  } catch (e) {
    return {
      code: -1,
      msg: '获取失败：' + e.message
    };
  }
};